package com.shujia.flink.core

import org.apache.flink.streaming.api.scala._

object Demo6CountWindow {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val linesDS: DataStream[String] = env.socketTextStream("master", 8888)

    /**
      * 统计窗口
      * 滑动和滚动
      *
      */

    linesDS
      .flatMap(_.split(","))
      .map((_, 1))
      .keyBy(_._1)
      .countWindow(10, 2)
      .sum(1)
      .print()


    env.execute()

  }
}
